#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <gmssl/sm3.h>

int main() {
    FILE *fp = fopen("sn.txt", "rb");
    if (!fp) {
        perror("fopen sn.txt");
        return 1;
    }

    SM3_CTX ctx;
    uint8_t dgst[SM3_DIGEST_SIZE];
    unsigned char buffer[4096];
    size_t n;

    sm3_init(&ctx);
    while ((n = fread(buffer, 1, sizeof(buffer), fp)) > 0) {
        sm3_update(&ctx, buffer, n);
    }
    fclose(fp);
    sm3_finish(&ctx, dgst);

    printf("SM3 摘要: ");
    for (int i = 0; i < SM3_DIGEST_SIZE; i++) {
        printf("%02x", dgst[i]);
    }
    printf("\n");
    return 0;
}
